#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QSystemTrayIcon>
#include <QCloseEvent>
#include "network/uploader.h"
#include <QTime>
#include <QtDeclarative/QDeclarativeView>
#include "accoutmanager.h"
#include <QProcess>
#include <QtSingleApplication/QtSingleApplication>

extern  QtSingleApplication* a;

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    enum Status{
        StatusError=-1,
        StatusIdle=0,
        StatusDowloading,
        StatusUploading,
        StatusTryPlay,
        StatusPlaying
    };

private:
    Ui::MainWindow *ui;
    QSystemTrayIcon *trayIcon;
    UpLoader *uploader;
    QTime *time;
    QTime *time2;
    AccoutManager* accmng;
    QProcess* game;
    QString Program;
    void DownloadUserData();
    QString bytesToSize(qint64 size);
    void pUpdate(QString value);
    Status State;
    void loadConfig();
    void StartAPP();

signals:
    void needToShow();

protected:
  void closeEvent(QCloseEvent *event);

public slots:
    void  handleMessage( const QString &  msg );

    ///////////////
    void activated ( QSystemTrayIcon::ActivationReason reason );
    void linkActivated (  );
    ////////////////Process///////////////////////////////////////////////
    void Pstarted();
    void Perror(QProcess::ProcessError error);
    void Pfinished(int exitCode, QProcess::ExitStatus exitStatus);

    ////////////////UI///////////////////////////////////////////////
    void Login();
    void Exit();

    ////////////////uploading////////////////////////////////////////
    void uploadProgress(qint64 bytesSent, qint64 bytesTotal);
    void uploadStarted();
    void authFinished(bool success, const QString &errortext);
    void uploadFinished(bool error, bool aborted, const QString &text);

    ////////////////downloading//////////////////////////////////////
    void downloadStarted(const QString &filename, const QString &size, const QString &fileurl);
    void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
    void downloadFinished(QString,bool,bool);

};

#endif // MAINWINDOW_H
